package jindu.zzh.gj.jinduriddle.riddle.view;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;


import jindu.zzh.gj.jinduriddle.R;
import jindu.zzh.gj.jinduriddle.riddle.Myapplication;

/**
 * Created by ZZH on 2018/11/18.
 */

public class OverActivity extends BaseAcitivity {
    private TextView tv_overdesc;
    private Handler handler = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_over);
        initView();
        Myapplication.error = 0;
        Myapplication.currentConut = 1;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("TAG", "OverActivity onNewIntent: ");
    }

    private void initView() {
        Typeface tfXingKai = Typeface.createFromAsset(getAssets(), "fonts/SIMKAI.TTF");
        tv_overdesc = findViewById(R.id.tv_overdesc);
        tv_overdesc.setTypeface(tfXingKai);
        ((TextView) findViewById(R.id.tv_overdesctext)).setTypeface(tfXingKai);
        String desc = "答题结束";
        int mipmapID;
        switch (Myapplication.error) {
            case 0:
                desc = "您3题都答对太棒了！";
                mipmapID = R.mipmap.z3;
                break;
            case 1:
                desc = "您答对2题，继续加油哦！";
                mipmapID = R.mipmap.z2;
                break;
            case 2:
                desc = "您只答对了1题，还需努力呢！";
                mipmapID = R.mipmap.z1;

                break;
            case 3:
                desc = "您全都没答对，可要和我学习更多的知识呢！";
                tv_overdesc.setTextSize(60);
                mipmapID = R.mipmap.z0;
                break;
            default:
                mipmapID = R.mipmap.z0;
        }
        tv_overdesc.setText(desc);
        tv_overdesc.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, mipmapID, 0);

    }

    @Override
    protected void onResume() {
        super.onResume();
        handler = new Handler();
        handler.postDelayed(this::restart, 10000);
    }

    public void restart() {
        startActivity(new Intent(this, HomeActivity.class));
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
        handler = null;
    }
}
